package com.auth.sdk.auth;

import com.auth.sdk.SpringContextUtil;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.Map;

/**
 * Auth manage
 *
 * @description: 选择一个 order 最小的实现类提供给切面执行
 * @author: cyj
 * @date 2021 -12-23 10:35:21
 *
 *
 */
@Component
public class AuthManage {

    /**
     * auth
     */
    public static IAuth auth;

    static {
        Map<String, IAuth> beansOfType = SpringContextUtil.applicationContext.getBeansOfType(IAuth.class);
        Collection<IAuth> auths = beansOfType.values();
        for (IAuth api : auths) {
            if (null == auth) {
                auth = api;
            } else {
                if (auth.getOrder() < api.getOrder()) {
                    auth = api;
                }
            }
        }
    }
}
